#!/usr/bin/python
# -*- coding: UTF-8 -*-

# pandas is a powerful data analysis and manipulation library for Python. It provides fast, flexible, and easy-to-use data structures for handling and analyzing data. In this tutorial, we will learn how to use pandas to read and manipulate data from a CSV file.

# First, we need to import the pandas library.

import pandas as pd

# Now, let's read a CSV file using pandas. We will use the `read_csv()` function to read the file. The function takes the file path as an argument and returns a DataFrame object.

# df = pd.read_csv('data.csv')
#
# # The `head()` function is a useful method to view the first few rows of the DataFrame.
#
# df.head()
#
# # We can also use the `info()` function to get a summary of the DataFrame, including the number of rows, columns, and data types.
#
# df.info()
#
# # We can also use the `describe()` function to get summary statistics for each column in the DataFrame.
#
# df.describe()
#
# # We can also use the `shape` attribute to get the number of rows and columns in the DataFrame.
#
# df.shape
#
# # Finally, we can use the `groupby()` function to group the data by a column and perform aggregate functions on the grouped data.
#
# df.groupby('column_name').agg(['mean','std', 'count'])

s = pd.Series([1, 2, 3, 4, 5])

data = [['tom', 80, 90], ['jerry', 70, 85], ['alice', 60, 75]]

df = pd.DataFrame(data, columns=['name', 'math', 'english'])

df.head()

df.info()

df.describe()

df.shape

df.groupby('name').agg(['mean','std', 'count'])

# We can also use the `to_csv()` function to write a DataFrame to a CSV file.

df.to_csv('new_data.csv', index=False)

# We can also use the `merge()` function to merge two DataFrames based on a common column.

# df1 = pd.DataFrame({'name': ['tom', 'jerry', 'alice'], 'age': [20, 25, 30]})
# df2 = pd.DataFrame({'name': ['tom', 'jerry', 'alice'], 'grade': ['A', 'B', 'C']})
#
# merged_df = pd.merge(df1, df2, on='name')
#
# print(merged_df)

# We can also use the `concat()` function to concatenate two or more DataFrames.
print(df)
